// pages/pay/pay.js
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    selectImg1:"../images/select.png",
    selectImg2: "../images/select.png",
    imgClick1: 0,
    imgClick2: 0,
    price:"0.00",
    info:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var info = JSON.parse(options.info)
    this.setData({
      info: info,
      price: options.price
    })
  },

  pay_click:function(e){
    //var time = util.formatTime(new Date());
    var that = this;
    console.log(that.data.info)
    wx.requestPayment({
      timeStamp: that.data.info.timeStamp,
      nonceStr: that.data.info.nonce_str,
      package: 'prepay_id=' + that.data.info.prepay_id,
      signType: 'MD5',
      paySign: that.data.info.paySign,
      success(res) {
        console.log(res)
        if (res.errMsg == "requestPayment:ok"){
          wx.showModal({
            title: '提示',
            content: '支付成功',
            showCancel: false,
            success(res) {
              //获取上一个页面
              var info = e.currentTarget.dataset.item
              let pages = getCurrentPages();
              let prevPage = pages[pages.length - 2];

              //刷新上一页面的数据
              prevPage.setData({
                up_adress: {
                  sAddress: '添加信息',
                  sPerson: "添加信息"
                },
                down_adress: {
                  sAddress: '添加信息',
                  sPerson: "添加信息"
                },
                numInput: "",
                remarkInput: "",
                price: 0.00,
                peopleNums: "请选择需要几个工人",
              })
              wx.navigateBack({
                delta: 1
              })
            }
          })
        }
       },
      fail(res) {
        console.log(res)
       }
    })
  },
  selcet_click1:function(e){
    var that = this;
    var times = e.currentTarget.dataset.id
    if (times == 0) {
      console.log("选中")
      that.setData({
        imgClick1: 1,
        selectImg1: "../images/selected.png",
      })
    } else {
      console.log("未选中")
      that.setData({
        imgClick1: 0,
        selectImg1: "../images/select.png",
      })
    }

  },
  selcet_click2: function (e) {
    var that = this;
    var times = e.currentTarget.dataset.id
    if (times == 0) {
      console.log("选中")
      that.setData({
        imgClick2: 1,
        selectImg2: "../images/selected.png",
      })
    } else {
      console.log("wei选中")
      that.setData({
        imgClick2: 0,
        selectImg2: "../images/select.png",
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})